<?
	require_once('includeC.php');
	
	//print_r($_REQUEST); //*********ONLY FOR DEBUGGING*************
	
	if(isset($_REQUEST['id']) && $_REQUEST['id'] != ''){
		$rs = GetUser($_REQUEST['id']);
		if($rs){
			$id = $rs['id'];
			$Name = $rs['Name'];
		}
	}
	
	if(isset($_REQUEST['isPostBack']) && $_REQUEST['isPostBack'] == true)
	{
		if(isset($_REQUEST['id']) && $_REQUEST['id'] != ''){
			$ValidationErrors = ValidateUser($_REQUEST);
			if(ValidateUser($_REQUEST) == null){
				EditUser($_REQUEST);
				header('location: indexC.php');
				die();
			}
			$Name = $_REQUEST['Name'];
		}
		else{
			if(ValidateUser($_REQUEST) == null){
				CreateUser($_REQUEST);
				header('location: indexC.php');
				die();
			}
			$Name = $_REQUEST['Name'];
		}
	}
	
	$conn->close();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Information</title>
</head>

<body>
	<!-- This is how to comment in html-->
    <ul class="error">
    	<? foreach($ValidationErrors as $key => $value) { ?>
        	<li> 
            	<?=$key?>: <?=$value?>
            </li>
        <? } ?>
    </ul>
	<form method="post">
    	<input type="hidden" name="id" value="<?=$id?>" />
    	<input type="hidden" name="isPostBack" value="true" />
        <div>
        	<label for="Name"> Course Name:</label>
        	<input type="text" name="Name" value="<?=$Name?>" id="Name" />
        </div>
        <input type="submit" value="Save" /> <br />
    </form>
</body>
</html>